#!/bin/bash

# Program:
#     User input a filename, program will check the flowing:
#     1.) exist? 2.) file/directory? 3.) file permission
# History:
#     2015/08/25    wxb    First release

echo -e "Please input a filename, I will check the filename's type and permission."
read -p "Input a filename : " filename

test -z $filename && echo "You MUST input a filename." && exit 0                 # -z : zero
test ! -e $filename && echo "The filename '$filename' DO NOT exist" && exit 0    # -e : exist
test -f $filename && filetype="regulare file"                                    # -f : file
test -d $filename && filetype="derectory"                                        # -d : directory
test -r $filename && perm="readable"                                             # -r : readable
test -w $filename && perm="$perm writable"                                       # -w : writable
test -x $filename && perm="$perm excutable"                                      # -x : excutable

echo "The filename: $filename is a $filetype"
echo "And the permission are : $perm"
